package com.cy.server.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.cy.server.dto.EmployeeDto;
import com.cy.server.dto.SalaryDto;
import com.cy.server.pojo.Employee;
import com.cy.server.pojo.RespBean;
import com.cy.server.pojo.Salary;
import com.cy.server.service.IEmployeeService;
import com.cy.server.service.ISalaryService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @peoject: yeb
 * @description: 员工工资账套
 * @author: LiShaoZhuo
 * @create: 2021-05-10 14:23
 **/
@RestController
@RequestMapping("/salary/sobcfg")
public class SalarySobCfgController {

    @Autowired
    ISalaryService salaryService;
    @Autowired
    IEmployeeService employeeService;

    @ApiOperation("查询工资账套信息")
    @PostMapping("/list")
    public RespBean selectSalary(@RequestBody SalaryDto salaryDto){
        PageInfo<Salary> pageInfo = salaryService.selectSalary(salaryDto);
        return RespBean.success(pageInfo);
    }

    @ApiOperation("查询员工账套")
    @PostMapping("/select")
    public RespBean selectEmployeeWithSalary(@RequestBody EmployeeDto employeeDto){
        PageInfo<Employee> pageInfo = employeeService.selectEmployeeWithSalary(employeeDto);
        return RespBean.success(pageInfo);
    }

    @ApiOperation("更新员工账套")
    @PostMapping("/update")
    public RespBean updateEmployeeSalary(Integer sid, Integer eid){
        if (employeeService.update(new UpdateWrapper<Employee>().set("salaryId", sid).eq("id", eid))){
            return RespBean.success("更新成功");
        }
        return RespBean.error("更新失败");
    }
}
